package tech.wetech.admin.service.system.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import tech.wetech.admin.common.base.Page;
import tech.wetech.admin.common.base.PageResultSet;
import tech.wetech.admin.mapper.system.BillMapper;
import tech.wetech.admin.mapper.system.PhotoMapper;
import tech.wetech.admin.model.system.Bill;
import tech.wetech.admin.model.system.BillExample;
import tech.wetech.admin.model.system.Photo;
import tech.wetech.admin.model.system.PhotoExample;
import tech.wetech.admin.service.system.PhotoService;

import java.util.ArrayList;
import java.util.List;

@Service
public class PhotoServiceImpl implements PhotoService {

   @Autowired
    private PhotoMapper photoMapper;
    @Override
    public int createPhoto(Photo photo) {
       return photoMapper.insert(photo);
    }

    @Override
    public PageResultSet<Photo> findByPage(Page page) {
        PhotoExample example = new PhotoExample();
        example.setOffset(page.getOffset());
        example.setLimit(page.getLimit());
        if (!StringUtils.isEmpty(page.getSearch())) {
            example.or().andNameLike("%" + page.getSearch() + "%");
        }
        long count = photoMapper.countByExample(example);
        List<Photo> dtoList = new ArrayList<>();
        PageResultSet<Photo> resultSet = new PageResultSet<Photo>();
        photoMapper.selectByExample(example).forEach(u -> {
            /*dto.setOrganizationName(getOrganizationName(Long.valueOf(dto.getOrganizationId())));
            dto.setRoleNames(getRoleNames(dto.getRoleIdList()));*/
            dtoList.add(u);
        });
        resultSet.setRows(dtoList);
        resultSet.setTotal(count);
        return resultSet;
    }

    @Override
    public int updatePhoto(Photo photo) {
        return photoMapper.updateByPrimaryKeySelective(photo);
    }

    @Override
    public void deletePhoto(Long id) {
        photoMapper.deleteByPrimaryKey(id);
    }

    @Override
    public Photo findById(Long id) {
        return photoMapper.selectByPrimaryKey(id);
    }
}
